/*
============================================================================
 Name        : PodcastUI.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CPodcastUI declaration
============================================================================
*/

#ifndef __PODCASTUI_H__
#define __PODCASTUI_H__

// INCLUDES
#include <e32std.h>
#include <e32base.h>

#include "MPluginContainer.h"
#include "ImageHandler.h"


class CWindowGc;
class CFbsBitmap;
class TRssFeed;
class TRssFeedItem;
class CTicker;
class CFbsBitmap;
class CImageHandler;


// CLASS DECLARATION
class CPodcastUI : public CBase, public MImageHandlerObserver
{
public: // Constructors and destructor
	~CPodcastUI();
	static CPodcastUI* NewL();
	static CPodcastUI* NewLC();

private:
	CPodcastUI();
	void ConstructL();

public:
	enum TPodcastTickerIcon
	{
		ENone,
		EPlay,
		EBuffering,
		EStop,
		EError
	};

private: //from MImageHandlerObserver
	void ImageIsReady(TInt aError);


public: //new functions
	void SelectNextItem();
	void SelectPreviousItem();

	void Draw(CWindowGc& aGc, const TRect& aRect) const;
	
	void SetTickerIcon(TPodcastTickerIcon aIcon);
	void SetTickerText(const TDesC& aText);
	void SetTickerTextFormat(TRefByValue<const TDesC16> aFmt, ...);

	void SetIsBuffering(TBool aIsBuffering, TInt aPercent);
	void SetImageUrl(const TDesC& aImageUrl, TCallBack& aOnFinishCallback);
	void SetIsPlaying(TBool aIsPlaying) { iIsPlaying = aIsPlaying; }

	void SetContainer(MPluginContainer* aContainer);
	void SetRssFeed(TRssFeed* aRssFeed);

	TRssFeedItem* GetSelectedItem();

	void Activate();
	void Deactivate();

	//Colors
	TRgb BackBorderColor() const { return TRgb(0xad5208); }
	TRgb BackShadowColor() const { return TRgb(0x9c4a00); }
	TRgb BackColor() const { return TRgb(0x7e3a00); } // 0xf7dece
	TRgb InsideBorderColor() const { return TRgb(0xffffff); }
	TRgb InsideColor() const { return TRgb(0xd67b31); }
	TRgb ForeColor() const { return TRgb(0x000000); }


private: //new functions
	void SelectItem(TBool aNextItem);


private: //data
	//Reference to parent
	MPluginContainer* iContainer;

	//Reference to rss feed
	TRssFeed* iRssFeed;

	//Bitmaps
	RPointerArray<CFbsBitmap> iBitmaps;

	//List box
	TInt iTopIndex;
	TInt iSelectedIndex;

	//Tickers
	CTicker* iTitle;
	CTicker* iItem;

	//Buffer
	TBool iIsBuffering;
	TInt iPercent;

	//Maximum number of list items 
	TInt iMaxNumItems;

	//Dimensions
	TInt iFontHeight;
	TInt iTextWidth;
	TSize iImageMaxSize;

	//Check if is playing or not
	TBool iIsPlaying;

	//Background image
	CFbsBitmap* iImage;
	CImageHandler* iImageHandler;
	TSize iImageSize;
	enum EImageResult
	{
		EImagePending,
		EImageReady,
		EImageFailed
	} iImageIsReady;

	//Callback after image is ready to be drawn
	TCallBack* iOnFinishCallback;
};

#endif // __PODCASTUI_H__
